package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
public class Greenhouse extends LogicEntity {
    @Column
    private String Name;
    @Column
    private String Address;
    @Column
    private Double Area;

    @OneToMany(mappedBy = "greenhouse",
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("greenhouse")
    private Set<Device> devices;

    public List<Device> getDevices() {
        List<Device> devices = new ArrayList<>();
        for (Device device : this.devices) {
            if (device.getIsDeleted() == 0) {
                devices.add(device);
            }
        }
        return devices;
    }
}
